#include <iostream>
#include <thread>
#include <future>

using namespace std;

int Add(int num1, int num2)
{
    cout << "Add" << endl;
    // this_thread::sleep_for(chrono::seconds(1));
    return num1 + num2;
}

int main()
{
    cout << "----------1-------------" << endl;
    // std::future<int> result = std::async(std::launch::deferred, Add, 12, 121); // deferred：调用get获取结果时，才进行执行
    std::future<int> result = std::async(std::launch::async, Add, 12, 121);    // async：创建任务成功就开始执行，get时若还没完成，就阻塞
    // this_thread::sleep_for(chrono::seconds(1));
    cout << "----------2-------------" << endl;
    int sum = result.get();
    cout << "----------3-------------" << endl;
    cout << "sum:" << sum << endl;
    cout << "----------4-------------" << endl;
    return 0;
}